package com.ruoyi.huoyun.bargain.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.huoyun.bargain.domain.PaymentAgreementInfo;
import com.ruoyi.huoyun.bargain.service.IPaymentAgreementInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 支付协议Controller
 *
 * @author mj
 * @date 2021-11-29
 */
@RestController
@RequestMapping("/bargain/payment")
public class PaymentAgreementInfoController extends BaseController
{
    @Autowired
    private IPaymentAgreementInfoService paymentAgreementInfoService;

    /**
     * 查询支付协议列表
     */
    @PreAuthorize("@ss.hasPermi('bargain:payment:list')")
    @GetMapping("/list")
    public TableDataInfo list(PaymentAgreementInfo paymentAgreementInfo)
    {
        startPage();
        List<PaymentAgreementInfo> list = paymentAgreementInfoService.selectPaymentAgreementInfoList(paymentAgreementInfo);
        return getDataTable(list);
    }

    /**
     * 导出支付协议列表
     */
    @PreAuthorize("@ss.hasPermi('bargain:payment:export')")
    @Log(title = "支付协议", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PaymentAgreementInfo paymentAgreementInfo)
    {
        List<PaymentAgreementInfo> list = paymentAgreementInfoService.selectPaymentAgreementInfoList(paymentAgreementInfo);
        ExcelUtil<PaymentAgreementInfo> util = new ExcelUtil<PaymentAgreementInfo>(PaymentAgreementInfo.class);
        util.exportExcel(response, list, "支付协议数据");
    }

    /**
     * 获取支付协议详细信息
     */
    @PreAuthorize("@ss.hasPermi('bargain:payment:query')")
    @GetMapping(value = "/{paymentAgreementId}")
    public AjaxResult getInfo(@PathVariable("paymentAgreementId") Integer paymentAgreementId)
    {
        return AjaxResult.success(paymentAgreementInfoService.selectPaymentAgreementInfoByPaymentAgreementId(paymentAgreementId));
    }

    /**
     * 新增支付协议
     */
    @PreAuthorize("@ss.hasPermi('bargain:payment:add')")
    @Log(title = "支付协议", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PaymentAgreementInfo paymentAgreementInfo)
    {
        return toAjax(paymentAgreementInfoService.insertPaymentAgreementInfo(paymentAgreementInfo));
    }

    /**
     * 修改支付协议
     */
    @PreAuthorize("@ss.hasPermi('bargain:payment:edit')")
    @Log(title = "支付协议", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PaymentAgreementInfo paymentAgreementInfo)
    {
        return toAjax(paymentAgreementInfoService.updatePaymentAgreementInfo(paymentAgreementInfo));
    }

    /**
     * 删除支付协议
     */
    @PreAuthorize("@ss.hasPermi('bargain:payment:remove')")
    @Log(title = "支付协议", businessType = BusinessType.DELETE)
	@DeleteMapping("/{paymentAgreementIds}")
    public AjaxResult remove(@PathVariable Integer[] paymentAgreementIds)
    {
        return toAjax(paymentAgreementInfoService.deletePaymentAgreementInfoByPaymentAgreementIds(paymentAgreementIds));
    }
}
